#include "stdafx.h"
#include "RenderState.h"

namespace a2d
{
//------------------------------------------------------------------
	
	RenderState::RenderState()
	{
	}

	void RenderState::SetTexture(GLuint TargetTexture, GLuint TextureID)
	{
		if ( TargetTexture != m_curtexture.TargetTexture || TextureID != m_curtexture.TextureID )
		{
			m_curtexture.TargetTexture = TargetTexture;
			m_curtexture.TextureID = TextureID;
			glBindTexture(m_curtexture.TargetTexture, m_curtexture.TextureID);
#if AS2D_RENDERSTATE_PROFILE
			printf("Texture set %d\n", TextureID);
#endif
		}
	}

	void RenderState::GetTexture(GLuint &TargetTexture, GLuint &TextureID)
	{
		TargetTexture = m_curtexture.TargetTexture;
		TextureID = m_curtexture.TextureID;
	}

	void RenderState::SetVAO(GLuint vao)
	{
		if ( m_vao != vao )
		{
			m_vao = vao;
			glBindVertexArray(m_vao);
#if AS2D_RENDERSTATE_PROFILE
			printf("VAO set %d\n", m_vao);
#endif
		}			
	}

	void RenderState::GetVAO(GLuint &vao)
	{
		vao = m_vao;
	}

	void RenderState::SetVBO(GLuint vbo)
	{
		if ( m_vb != vbo )
		{
			m_vb = vbo;
			glBindBuffer(GL_ARRAY_BUFFER, m_vb);
#if AS2D_RENDERSTATE_PROFILE
			printf("VB set %d\n", m_vb);
#endif
		}
	}

	void RenderState::SetVBO(GLuint vb, GLuint ib)
	{
		SetVBO(vb);

		if ( m_ib != ib )
		{
			m_ib = ib;
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ib);
#if AS2D_RENDERSTATE_PROFILE
			printf("IB set %d\n", m_ib);
#endif
		}
	}

	void RenderState::GetVBO(GLuint &vbo)
	{
		vbo = m_vb;
	}

	void RenderState::SetShaderProgram(GLuint program)
	{
		if ( m_program != program )
		{
			m_program = program;
			glUseProgram(m_program);
#if AS2D_RENDERSTATE_PROFILE
			printf("Shader program set %d\n", m_program);
#endif
		}
	}

	void RenderState::GetShaderProgram(GLuint &program)
	{
		program = m_program;
	}

	

//------------------------------------------------------------------
} // namespace a2d
